package com.yt.lxh.acl.controller;

import com.yt.lxh.acl.service.MenuService;
import com.yt.lxh.common.result.Result;
import com.yt.lxh.common.result.ResultCodeEnum;
import com.yt.lxh.model.acl.Menu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜单接口")
@RestController
@RequestMapping("/admin/acl/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @ApiOperation("菜单删除")
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        menuService.deleteById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("菜单修改")
    @PutMapping("/update")
    public Result update(@RequestBody Menu menu,
                         @RequestHeader(name = "token") String token){
        menuService.updateMenuById(menu,token);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("菜单添加")
    @PostMapping("/save")
    public Result save(@RequestBody Menu menu,
                       @RequestHeader(name = "token") String token){
        menuService.saveMenu(menu,token);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("菜单列表")
    @GetMapping("/findNodes")
    public Result<List<Menu>> findNodes(){
        List<Menu> list = menuService.findNodes();
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }
}
